package com.bestcem.xm.ticket.service.convert;

import com.bestcem.xm.ticket.dao.dto.TicketInfo;
import com.bestcem.xm.ticket.entity.mongo.Ticket;
import org.springframework.util.CollectionUtils;

import java.util.LinkedList;

/**
 * entity => DTO
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/9/9 22:28
 */
public class TicketInfoConvert {

    /**
     * 实体类转换为Info
     */
    public static TicketInfo entityToInfo(Ticket entity) {
        if (entity == null) {
            return null;
        }

        TicketInfo data = new TicketInfo();

        data.setId(entity.getId());
        data.setRecordFlag(entity.getRecordFlag());
        data.setCreatedDate(entity.getCreatedDate());
        data.setCreatedId(entity.getCreatedId());
        data.setUpdatedDate(entity.getUpdatedDate());
        data.setUpdatedId(entity.getUpdatedId());
        data.setName(entity.getName());
        data.setSysId(entity.getSysId());
        data.setOrgId(entity.getOrgId());
        data.setTicketNo(entity.getTicketNo());
        data.setSurveyId(entity.getSurveyId());
        data.setSurveyTitle(entity.getSurveyTitle());
        data.setFollowRoleId(entity.getFollowRoleId());
        data.setFollowUserIds(entity.getFollowUserIds());
        if (CollectionUtils.isEmpty(data.getFollowUserIds())) {
            data.setFollowUserIds(new LinkedList<>());
        }
        data.setAuditUserIds(entity.getAuditUserIds());
        if (CollectionUtils.isEmpty(data.getAuditUserIds())) {
            data.setAuditUserIds(new LinkedList<>());
        }
        data.setAuditRoleId(entity.getAuditRoleId());
        data.setCurrentFollowNode(entity.getCurrentFollowNode());
        data.setFollowNodeCount(entity.getFollowNodeCount());
        data.setCurrentAuditNode(entity.getCurrentAuditNode());
        data.setAuditNodeCount(entity.getAuditNodeCount());
        data.setRegion(entity.getRegion());
        data.setRegionName(entity.getRegionName());
        data.setAlertId(entity.getAlertId());
        data.setAlertRuleIds(entity.getAlertRuleIds());
        if (CollectionUtils.isEmpty(data.getAlertRuleIds())) {
            data.setAlertRuleIds(new LinkedList<>());
        }
        data.setResId(entity.getResId());
        data.setContact(entity.getContact());
        data.setStatus(entity.getStatus());
        data.setHasFollowOverdue(entity.getHasFollowOverdue());
        data.setFollowDeadline(entity.getFollowDeadline());
        data.setHasAuditOverdue(entity.getHasAuditOverdue());
        data.setAuditDeadline(entity.getAuditDeadline());
        data.setTicketDeadline(entity.getTicketDeadline());
        data.setTicketConfigId(entity.getTicketConfigId());
        data.setTicketFlow(entity.getTicketFlow());
        data.setTicketTemplate(entity.getTicketTemplate());
        data.setTicketTemplateV2(entity.getTicketTemplateV2());
        data.setTicketRecordIds(entity.getTicketRecordIds());
        if (CollectionUtils.isEmpty(data.getTicketRecordIds())) {
            data.setTicketRecordIds(new LinkedList<>());
        }
        data.setClosedDate(entity.getClosedDate());
        data.setTicketFlowList(entity.getTicketFlowList());
        if (CollectionUtils.isEmpty(data.getTicketFlowList())) {
            data.setTicketFlowList(new LinkedList<>());
        }
        data.setTicketFinishTime(entity.getTicketFinishTime());
        data.setTicketFailedTime(entity.getTicketFailedTime());
        data.setCurFollowUserId(entity.getCurFollowUserId());
        if (CollectionUtils.isEmpty(data.getCurFollowUserId())) {
            data.setCurFollowUserId(new LinkedList<>());
        }
        data.setTemplateDetailFields(entity.getTemplateDetailFields());
        if (CollectionUtils.isEmpty(data.getTemplateDetailFields())) {
            data.setTemplateDetailFields(new LinkedList<>());
        }
        data.setNeedRecord(entity.getNeedRecord());
        data.setType(entity.getType());
        data.setHasCommit(entity.getHasCommit());
        data.setMemberId(entity.getMemberId());
        data.setDetailTemplateId(entity.getDetailTemplateId());
        data.setHandleTemplateId(entity.getHandleTemplateId());
        data.setOperationType(entity.getOperationType());
        data.setCreatedName(entity.getCreatedName());
        // 工单满足的触发条件的名称 2022-02-18 行动新增条件名称需求新增
        data.setTriggerNames(entity.getTriggerNames());
        if (CollectionUtils.isEmpty(data.getTriggerNames())) {
            data.setTriggerNames(new LinkedList<>());
        }

        return data;
    }
}
